<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2017/10/10
 * Time: 15:20
 */
namespace Admin\Controller;
class RoleController extends BaseController{
    /*角色列表*/
    public function lst(){
        $model=D('Group');
        $roles=$model->getlst();
        //sb($roles);exit();
        $this->roles=$roles;
        $this->display();
    }
    /*角色添加*/
    public function add(){
        if(IS_POST){
            $mod=D('Group');
            if(!$mod->validate($mod->_regist_validate)->create(I('POST.'))){
                $err=$mod->getError();
                $this->error($err);
            }else{
                if($mod->add()){
                    $this->success('success!',U('lst'),1);
                    exit;
                }else{
                    $this->error('faile!',U('lst'),1);
                    exit;
                }
            }
        }
        $this->display();
    }
    /*角色编辑*/
    public function edit()
    {
        $id = I('get.id');
        if(IS_POST)
        {
            $model = D('Group');
            if($model->create(I('post.'), 2))
            {
                if($model->save() !== FALSE)
                {
                    $this->success('修改成功！', U('lst', array('p' => I('get.p', 1))));
                    exit;
                }
            }
            $this->error($model->getError());
        }
        $model = new \Model\AdminModel();
        $data = $model->find($id);
        $this->assign('data', $data);
        $ramodel=D('admin_role');
        $radata=$ramodel->field('role_id')->where(array('admin_id'=>array('eq',$id)))->select();
//		sb($radata);exit;
        $rmodel=D('role');
        $rdata=$rmodel->select();
        // 设置页面中的信息
        $this->assign(array(
            'radata'=>$radata,
            'rdata'=>$rdata,
            '_page_title' => '修改',
            '_page_btn_name' => '列表',
            '_page_btn_link' => U('lst'),
        ));
        $this->display();
    }
}